<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input id="id" name="id" th:value="${thirdSdk.id}" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">渠道名称：</label>
                            <div class="col-sm-8">
                                <input readonly="readonly" id="channelname" name="channelname"
                                       th:value="${thirdSdk.channelname}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">sdk名称：</label>
                            <div class="col-sm-8">
                                <input readonly="readonly" id="sdkname" name="sdkname" th:value="${thirdSdk.sdkname}"
                                       class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">变现方名称：</label>
                            <div class="col-sm-8">
                                <input maxlength="50" id="thirdname" name="thirdname" th:value="${thirdSdk.thirdname}"
                                       class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">变现方sdk版本号：</label>
                            <div class="col-sm-8">
                                <input onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')"
                                       maxlength="50" id="thirdsdkver" name="thirdsdkver"
                                       th:value="${thirdSdk.thirdsdkver}"
                                       class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否运营：</label>
                            <div class="col-sm-8">
                                <select id="isoperate" name="isoperate" class="form-control">
                                    <option value="1">运营</option>
                                    <option value="0">不运营</option>
                                </select>
                            </div>
                            <input id="isoperatehidden" name="isoperatehidden" th:value="${thirdSdk.isoperate}"
                                   type="hidden">
                        </div>
                        <div class="form-group" id="dddddd">
                            <label class="col-sm-3 control-label">sdk包名：</label>
                            <div class="col-sm-8">
                                <input maxlength="50" id="sdkpackname" name="sdkpackname"
                                       th:value="${thirdSdk.sdkpackname}"
                                       class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group" id="bbbbbb">
                            <label class="col-sm-3 control-label">sdk方法名：</label>
                            <div class="col-sm-8">
                                <input maxlength="50" id="sdkmethodname" name="sdkmethodname"
                                       th:value="${thirdSdk.sdkmethodname}"
                                       class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否控量：</label>
                            <div class="col-sm-8">
                                <select onchange="getControlquantity()" id="iscontrolquantity" name="iscontrolquantity"
                                        class="form-control">
                                    <option value="1">控量</option>
                                    <option value="0">不控量</option>
                                </select>
                            </div>
                            <input id="iscontrolquantityhidden" name="iscontrolquantityhidden"
                                   th:value="${thirdSdk.iscontrolquantity}"
                                   type="hidden">
                        </div>
                        <div id="aaaaa" class="form-group">
                            <label class="col-sm-3 control-label">控制数量：</label>
                            <div class="col-sm-8">
                                <input maxlength="10" onkeyup="this.value=this.value.replace(/\D/g,'')"
                                       onafterpaste="this.value=this.value.replace(/\D/g,'')" id="controlquantity"
                                       name="controlquantity"
                                       th:value="${thirdSdk.controlquantity}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group" id="cccccc">
                            <form enctype="multipart/form-data" method="post"
                                  id="updform">
                                <div class="form-group">
                                    <label class="col-md-3 control-label">上传文件</label>
                                    <div class="col-md-9">
                                        <input type="file" id="file" name="file" style="display: inline-block;">
                                        <a id="apkUrl" style="margin-right: 50px;" href="javascript:void(0);"></a>
                                        <button type="button" class="btn btn-primary " id="upload">
                                            上传
                                        </button>
                                        <p class="help-block">请上传相关渠道包.</p>
                                    </div>

                                </div>
                            </form>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">描述：</label>
                            <div class="col-sm-8">
                                <input maxlength="150" id="sdkdes" name="sdkdes" th:value="${thirdSdk.sdkdes}"
                                       class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <input id="sdktype" name="sdktype" th:value="${thirdSdk.sdktype}" type="hidden">
                        <input type="hidden" name="sdkurl" id="fileUrl"/>
                        <input type="hidden" name="thirdsdkname" id="fileName"/>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript" src="/js/appjs/market/thirdSdk/edit.js">
</script>
<script type="text/javascript" th:inline="javascript">
    function getControlquantity() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        var channelid = $("#iscontrolquantity").val();
        if (channelid == 0) {
            $("#controlquantity").val('');
            $("#signupForm").validate({
                rules: {
                    controlquantity: {
                        required: false
                    }
                }
                ,
                messages: {
                    controlquantity: {
                        required: icon + "请输入控制数量"
                    }

                }
            })

            $("#aaaaa").hide();
        } else {
            $("#aaaaa").show();
            $("#signupForm").validate({
                rules: {
                    controlquantity: {
                        required: true
                    }
                }
                ,
                messages: {
                    controlquantity: {
                        required: icon + "请输入控制数量"
                    }

                }
            })
        }
    }

    function downFileUrl(fileUrl) {
        window.location.href = "/market/thirdSdk/downFile?fileUrl=" + fileUrl;
    }

    $(function () {
        $("#apkUrl").text([[${thirdSdk.thirdsdkname}]]);
        $("#apkUrl").attr("onclick", "").click(function () {
            downFileUrl([[${thirdSdk.sdkurl}]]);
        });
        $("#fileUrl").val([[${thirdSdk.sdkurl}]]);
        $("#fileName").val([[${thirdSdk.thirdsdkname}]]);

        var sdktype = $("#sdktype").val()
        if (sdktype == 0) {
            $("#dddddd").hide();
            $("#bbbbbb").hide();
            $("#cccccc").hide();
        }
        $("#upload").click(function () {
            var oFile = $("#file").val();
            if (oFile == null || "" == oFile) {
                alert("没有文件！请选择或退出");
                return;
            }
            var file = document.querySelector('[type=file]');
            // 通过FormData将文件转成二进制数据
            var formData = new FormData();
            // 将文件转二进制
            formData.append('file', file.files[0]);
            // var bbb = $("#updform:first").serialize()
            // var aaa = new FormData($("#file")[0]);
            // var form = new FormData(document.getElementById("updform"));
            $.ajax({
                type: "POST",
                url: "/market/thirdSdk/uploadFile",
                data: formData,// 你的formid
                async: false,
                processData: false,
                contentType: false,
                error: function (request) {
                    parent.layer.alert("Connection error");
                },
                success: function (result) {
                    if (result != null) {
                        var name = result.split("#")[0];
                        var url = result.split("#")[1];
                        $("#apkUrl").text(name);
                        $("#apkUrl").attr("onclick", "").click(function () {
                            downFileUrl(url);
                        });
                        $("#fileUrl").val(url);
                        $("#fileName").val(name);
                        layer.msg("上传成功");
                        $("#file").val('');
                    } else {
                        layer.msg("上传失败，请联系管理员！");
                    }
                }
            });
        });
    })
</script>

</body>
</html>
